<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<html>
<head><title>Zadanie 5</title></head>
<body>

<%!
    public static int day(int M, int D, int Y) {
        int y = Y - (14 - M) / 12;
        int x = y + y / 4 - y / 100 + y / 400;
        int m = M + 12 * ((14 - M) / 12) - 2;
        int d = (D + x + (31 * m) / 12) % 7;
        return d;
    }

    public static boolean isLeapYear(int year) {
        if ((year % 4 == 0) && (year % 100 != 0)) return true;
        if (year % 400 == 0) return true;
        return false;
    }
%>
<pre>
Trzeba jeszcze zminimalizowasc ilosc kodu javy :D<br/>    
<%
    int Y = 2007;
    String[] months = {"", "January", "February", "March", "April", "May",
            "June", "July", "August", "September", "October",
            "November", "December"};

    int[] days = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    if (isLeapYear(Y)) days[2] = 29;

    for (int M = 1; M <= 12; M++) {
        out.println("   " + months[M] + " " + Y + "<br/>");
        out.println(" S  M  T  W Th  F  S <br />");

        // check for leap year

        // starting day
        int d = day(M, 1, Y);

        // print the calendar
        for (int i = 0; i < d; i++)
            out.print("   ");
        for (int i = 1; i <= days[M]; i++) {
            if (i < 10) out.print(" ");   // printf("%2d ", i);
            out.print(i);
            out.print(" ");
            if (((i + d) % 7 == 0) || (i == days[M])) out.println("<br/>");
        }
        out.println("<br/><br/>");
    }
%>
</pre>

</body>
</html>